home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 701-725 / 708 / intuisup / intuisup42.lha / Intuisup / source.lha / Files / files_test.c next >
C/C++ Source or Header  |  1992-04-11  |  2KB  |  86 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: files_test.c
  6.  *    Created ..: Thursday 19-Dec-91 20:01:01
  7.  *    Revision .: 0
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    11-Apr-92   Torsten Jürgeleit      changed line too long error msg
  12.  *    19-Dec-91   Torsten Jürgeleit      Created this file!
  13.  *
  14.  ****************************************************************************
  15.  *
  16.  *    Test for text file functions
  17.  *
  18.  * $Revision Header ********************************************************/
  19.  
  20.     /* Includes */
  21.  
  22. #include <exec/types.h>
  23. #ifdef AZTEC_C
  24. #include <functions.h>   /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
  25. #endif
  26. #include <libraries/memwatch.h>   /* header file for memory debug link library (Fish 240) - AFTER functions.h */
  27. #include <stdio.h>
  28. #include "files.h"
  29.  
  30.     /* Defines */
  31.  
  32. #define FILE_NAME        "test_file"
  33. #define FILE_READ_BUFFER_SIZE    2000
  34. #define FILE_LINE_BUFFER_SIZE    100
  35. #define FILE_FLAGS        (TEXT_FILE_FLAG_TRIM_LINE | TEXT_FILE_FLAG_SKIP_COMMENTS | TEXT_FILE_FLAG_SKIP_EMPTY_LINES | TEXT_FILE_FLAG_LINE_CONTINUATION)
  36.  
  37.     /* Text file test */
  38.  
  39.    LONG
  40. main(VOID)
  41. {
  42.    struct FileData  *fd;
  43.    BYTE *error = NULL;
  44.    LONG arg1, arg2;
  45.  
  46.    MWInit((BPTR)NULL, 0L);
  47.    if (!(fd = open_text_file(FILE_NAME, FILE_READ_BUFFER_SIZE,
  48.                       FILE_LINE_BUFFER_SIZE, FILE_FLAGS))) {
  49.       error = "Can't open file `%s'\n";
  50.       arg1  = (LONG)FILE_NAME;
  51.    } else {
  52.       SHORT status;
  53.  
  54.       do {
  55.      switch(status = read_text_line(fd)) {
  56.         case TEXT_FILE_STATUS_NORMAL :
  57.            printf("Line %d: `%s'\n", fd->fd_LineNum, fd->fd_Line);
  58.  
  59.         case TEXT_FILE_STATUS_EOF :
  60.            break;
  61.  
  62.         case TEXT_FILE_ERROR_LINE_TOO_LONG :
  63.            error = "Line %ld too long (>%ld)\n";
  64.            arg1  = fd->fd_LineNum;
  65.            arg2  = FILE_LINE_BUFFER_SIZE;
  66.            break;
  67.  
  68.         case TEXT_FILE_ERROR_NO_COMMENT_END :
  69.            error = "Missing end of comment `*/' in line %ld\n";
  70.            arg1  = fd->fd_LineNum;
  71.            break;
  72.  
  73.         case TEXT_FILE_ERROR_READ_FAILED :
  74.            error = "Error while reading\n";
  75.            break;
  76.      }
  77.       } while (status == TEXT_FILE_STATUS_NORMAL);
  78.       close_text_file(fd);
  79.    }
  80.    if (error) {
  81.       printf(error, arg1, arg2);
  82.    }
  83.    MWTerm();
  84.    return(0L);
  85. }
  86.